package com.qjc.demo.base.collection;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Description:
 * @Author: qjc
 * @Date: 2020/7/31
 */
public class ListTest {

    public static void main(String[] args) {
        //不安全的List
        ArrayList<String> stringList = new ArrayList<>();
        for (int i = 1; i <= 22; i++) {
            stringList.add(String.valueOf(i));
        }
        //安全的List1
        Vector<String> vector = new Vector<>();
        for (int i = 1; i <= 22; i++) {
            vector.add(String.valueOf(i));
        }
        vector.get(0);
        vector.size();
        //安全的List2
        List<String> synchronizedList = Collections.synchronizedList(new ArrayList<>());
        for (int i = 1; i <= 22; i++) {
            synchronizedList.add(String.valueOf(i));
        }
        synchronizedList.get(0);
        //安全的List3
        CopyOnWriteArrayList<String> copyOnWriteArrayList = new CopyOnWriteArrayList<>();
        for (int i = 1; i <= 22; i++) {
            copyOnWriteArrayList.add(String.valueOf(i));
        }
        copyOnWriteArrayList.get(0);


        List<String> linkedList = new LinkedList<>();
        for (int i = 0; i < 22; i++) {
            linkedList.add(String.valueOf(i));
        }
        linkedList.add(10, "10");

    }

}
